<?php
    session_start();
    require("../inc/db.class.php");
	require("../inc/functions.php");
    $title= security_on($_POST['title']);
    $description = security_on($_POST['description']);
	$start_date = security_on($_POST['start_date']);
	$end_date = security_on($_POST['end_date']);
    $created_by = security_on($_POST['created_by']);
	$created_at = security_on($_POST['created_at']);
	$modified_at = date('Y-m-d h:i:s');
	$venue = security_on($_POST['venue']);
	$start_date = date('Y-m-d H:i:s', strtotime($start_date));
	$end_date = date('Y-m-d H:i:s', strtotime($end_date));
 
    $dbo= new database();
 if(isset($_POST['add'])){
  $insertEvent ="insert into  ".DB_NAME.".events (`title`, `description`, `start_date`, `end_date`, `created_by`, `created_at`, `modified_at`, `venue`) values('$title', '$description', '$start_date', '$end_date', '$created_by', '$created_at', '$modified_at', '$venue') ";
	echo $insertEvent; 
 if($dbo->query($insertEvent))
 header("location: ../admin-events.php?add=1");
  else
    header("location: ../admin-events.php?add=0");
 } else {
  $id = $_POST['id'];
  $updateEvent ="UPDATE  ".DB_NAME.".Events SET `title`='$title', `description`='$description', `modified_at`='$modified_at' WHERE `id` =$id";
  if($dbo->query($updateEvent))
    header("location: ../admin-events.php?update=1");
  else
    header("location: ../admin-events.php?update=0");

 }
        
        
?>